package com.yidu.hbatsft.action;

import com.yidu.hbatsft.domain.AtsScheme;
import com.yidu.hbatsft.domain.AtsSchemeAthlete;
import com.yidu.hbatsft.service.AtsSchemeAthleteService;
import com.yidu.hbatsft.service.AtsSchemeService;
import com.yidu.privilege.Utils.BaseMessage;
import com.yidu.privilege.Utils.Pages;
import com.yidu.utils.Page;
import com.yidu.utils.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/UserseController")
public class AtsSchemeAthleteController {

    //方案对应的运动员表
    @Resource
    AtsSchemeAthleteService atsSchemeAthleteService;

   @Resource
    AtsSchemeService service;



    @RequestMapping("select2")
    @ResponseBody
   public List<AtsScheme> select(AtsScheme atsScheme){
     List<AtsScheme>  list = service.selectfindAll(atsScheme);
     return list;
   }




    /**
     * 查询所有分页
     * @param pages
     * @param vo
     * @return
     */
    @ResponseBody
    @RequestMapping("selectAll")
    public Map<String, Object> findAll(Pages pages, AtsSchemeAthlete vo) {

        /*logger.error(pages.getPage() + "===============================" + pages.getLimit());
        logger.info("进来了............" + pages.getTotalRows());*/
        Map<String, Object> map = new HashMap<String, Object>();

        long count = atsSchemeAthleteService.count(vo).intValue();

        pages.setTotalRows(atsSchemeAthleteService.count(vo).intValue());
        if (pages.getStartRows()== 0) {
            pages.setStartRows(1);
        }
        List<AtsSchemeAthlete> list = atsSchemeAthleteService.selectAll(vo, pages);

        System.out.println("------------------------+"+list);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count); // 总行数
        map.put("data", list);
        return map;

    }

    /**
     * 新增和修改
     * @param vo
     * @return
     */
    @ResponseBody
    @RequestMapping("insert")
    public BaseMessage add(AtsSchemeAthlete vo){

        BaseMessage bm = new BaseMessage();
        System.out.println("saasdsaassassa:"+vo.getSaId()+"asASAS"+vo.getAthleteName());
        String id = Tools.getRandomUUID();
        if(vo.getSaId() != null && !"".equals(vo.getSaId())){
            atsSchemeAthleteService.updateByPrimaryKey(vo);
        }else {
            vo.setCreatTime(new Date());
            vo.setSaId(Integer.valueOf(id));
            bm.setState(1);
            atsSchemeAthleteService.insert(vo);
        }
        bm.setMsg("操作成功!");
        return bm;
    }

    /**
     * 逻辑删除
     *
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public BaseMessage delete(Integer saId){
        int vo =  atsSchemeAthleteService.update(saId);
        BaseMessage mes = new BaseMessage();
        mes.setState(1);
        mes.setMsg("删除成功!");
        return mes;
    }

    /**
     * 修改显示  根据id查询
     * @return
     */
    @RequestMapping("select")
    @ResponseBody
    public AtsSchemeAthlete select(Integer saId){
        AtsSchemeAthlete vo =  atsSchemeAthleteService.selectByPrimaryKey(saId);
        return vo;
    }


    /**
     * 模糊查询
     */
    @ResponseBody
    @RequestMapping("selectVague")
    public Map<String, Object> selectVague(Pages pages, AtsSchemeAthlete vo,String newsTitle) {

        /*logger.error(pages.getPage() + "===============================" + pages.getLimit());
        logger.info("进来了............" + pages.getTotalRows());*/
        Map<String, Object> map = new HashMap<String, Object>();

        long count = atsSchemeAthleteService.count(vo).intValue();

        pages.setTotalRows(atsSchemeAthleteService.count(vo).intValue());
        if (pages.getStartRows()== 0) {
            pages.setStartRows(1);
        }
        vo.setSchemeName(newsTitle);
        System.out.println("00000000000000000000000000000000000000000000000"+newsTitle);
        List<AtsSchemeAthlete> list = atsSchemeAthleteService.selectVague(newsTitle);

        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count); // 总行数
        map.put("data", list);
        return map;

    }

    /**
     * 根据方案id查询
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("selectbyschemeidKF")
    public Map<String, Object> selectbyschemeidKF(Integer id){
        System.out.println("执行根据方案id查询方法");
        List<AtsSchemeAthlete> list =atsSchemeAthleteService.selectbyschemeidKF(Integer.valueOf(id));
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",list.size());
        map.put("data",list);
        return map;
    }
}
